﻿using System;
using System.Collections.Generic;
using System.Linq;
using Mal.Balades.Admin.Repositories;
using Mal.Balades.Admin.Services;

namespace Mal.Balades.Admin.ViewModels.VisitViewModels.Edit
{
    public class PictureViewModel : DataViewModelBase
    {
        #region Fields
        IPicture _picture;
        int? pictureID;
        int? pictureTypeID;
        int? visitID;
        string title;
        string text;
        string url;
        int? rank;

        private List<IPictureType> pictureTypes;
        private IPictureType selectedPictureType;


        #endregion

        #region Construction / Destruction
        public PictureViewModel()
        {
            Initialize();
        }

        public PictureViewModel(IPicture picture)
            : this()
        {
            this.Picture = picture;
        }
        #endregion

        #region enum, struct, class
       
        #endregion

        #region Properties
        private IPicture Picture
        {
            get { return _picture; }
            set
            {
                _picture = value;
                //RaisePropertyChanged("Picture");
                this.PictureID = _picture.PictureID;
                this.PictureTypeID = _picture.PictureTypeID;
                this.Rank = _picture.Rank;
                this.Text = _picture.Text;
                this.Title = _picture.Title;
                this.Url = _picture.Url;
                this.VisitID = _picture.VisitID;
            }
        }

        public int? PictureID
        {
            get { return pictureID; }
            set
            {
                pictureID = value;
                RaisePropertyChanged("PictureID");
            }
        }

        public int? VisitID
        {
            get { return visitID; }
            set
            {
                visitID = value;
                RaisePropertyChanged("VisitID");
            }
        }

        public int? PictureTypeID
        {
            get { return pictureTypeID; }
            set
            {
                pictureTypeID = value;
                RaisePropertyChanged("PictureTypeID");

                this.SelectedPictureType = this.PictureTypes.FirstOrDefault(i => i.PictureTypeID == pictureTypeID);

            }
        }

        public int? Rank
        {
            get { return rank; }
            set
            {
                rank = value;
                RaisePropertyChanged("Rank");
            }
        }

        public String Text
        {
            get { return text; }
            set
            {
                text = value;
                RaisePropertyChanged("Text");
            }
        }

        public String Title
        {
            get { return title; }
            set
            {
                title = value;
                RaisePropertyChanged("Title");
            }
        }

        public String Url
        {
            get { return url; }
            set
            {
                url = value;
                RaisePropertyChanged("Url");
                RaisePropertyChanged("FileUrl");
            }
        }

        public string FileUrl
        {
            get
            {
                return string.Format("http://autourdeaix.free.fr/photos/{0}.jpg", this.Url);
            }
        }

        public IPictureType SelectedPictureType
        {
            get { return selectedPictureType; }
            set
            {
                if (selectedPictureType != value)
                {
                    selectedPictureType = value;
                    RaisePropertyChanged("SelectedPictureType");

                    this.PictureTypeID = selectedPictureType.PictureTypeID;
                }
            }
        }

        public List<IPictureType> PictureTypes
        {
            get { return pictureTypes; }
            set
            {
                if (pictureTypes != value)
                {
                    pictureTypes = value;
                    RaisePropertyChanged("PictureTypes");
                }
            }
        }
        #endregion

        #region Methods
        protected override bool GetIsChanged()
        {
            return false;
        }

        private void Initialize()
        {
            this.PictureTypes = Repository.Instance.PictureTypes.Datas;

          }
        #endregion

        #region Events

        #endregion


    }
}
